<#--
  Frontend API WithUI 辅助方法
-->

/**
 * 导出${table.comment!table.entityName}（带UI交互）
 */
export const export${table.entityName}WithUI = async (params: any) => {
  try {
    await ${lowerEntity}Api.export${table.entityName}(params)
    ElMessage.success('导出成功')
  } catch (error) {
    console.error('导出失败:', error)
    ElMessage.error('导出失败')
  }
}

/**
 * 导入${table.comment!table.entityName}（带UI交互）
 */
export const import${table.entityName}WithUI = async (
  file: File,
  updateSupport: boolean,
  callback?: () => void
) => {
  // 验证文件
  if (!validateExcelFile(file)) {
    return
  }

  try {
    const response = await ${lowerEntity}Api.import${table.entityName}(file, updateSupport)
    const result = response.data
    
    // 显示导入结果
    if (result.failureCount > 0) {
      ElMessageBox.alert(
        `导入完成！成功: ${'$'}{result.successCount}, 失败: ${'$'}{result.failureCount}`,
        '导入结果',
        {
          dangerouslyUseHTMLString: true,
          type: 'warning'
        }
      )
    } else {
      ElMessage.success(`导入成功！共导入 ${'$'}{result.successCount} 条数据`)
    }
    
    // 执行回调
    if (callback) {
      callback()
    }
  } catch (error) {
    console.error('导入失败:', error)
    ElMessage.error('导入失败')
  }
}

/**
 * 下载${table.comment!table.entityName}导入模板（带UI交互）
 */
export const download${table.entityName}TemplateWithUI = async () => {
  try {
    await ${lowerEntity}Api.download${table.entityName}Template()
    ElMessage.success('模板下载成功')
  } catch (error) {
    console.error('下载模板失败:', error)
    ElMessage.error('下载模板失败')
  }
}


